package com.training.admin.entity.project;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.hibernate.annotations.Type;
import org.springframework.format.annotation.DateTimeFormat;

import com.demo2do.core.format.PersistentFormat;
import com.training.admin.entity.category.TrainingCategory;
import com.training.admin.entity.department.Department;


/**
 * 培训项目
 * 
 * @author Rockett
 *
 */
@Entity
@Table(name = "project")
public class Project {
    
	/**
	 * ID
	 */
    @Id
    @GeneratedValue
    private Long id;
    
    /**
     * 项目名称
     */
    private String name;
    
    /**
     * 项目编号
     */
    private String code;
    
    /**
     * 一级分类
     */
    @ManyToOne(fetch = FetchType.LAZY, optional = false)
    @PersistentFormat
    private TrainingCategory firstCategory;
    
    /**
     * 二级分类
     */
    @PersistentFormat
    @ManyToOne(fetch = FetchType.LAZY, optional = false)
    private TrainingCategory secondCategory;
    
    /**
     * 期数
     */
    private int phaseCount;
    
    /**
     * 项目负责人
     * 
     */
    private String projectLead;
    
    private String projectLeadEmail;

    /**
     * 部门
     */
    @ManyToOne(fetch = FetchType.LAZY, optional = true)
    @PersistentFormat
    private Department department;

    /**
     * 
     */
    @Column(name = "is_disabled")
    private boolean disabled;
    
    /**
     * 开始日期
     */
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @Type(type = "date")
    private Date beginDate;

    /**
     * 结束日期
     */
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @Type(type = "date")
    private Date endDate;
    
    /**
     * 创建日期
     */
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date createTime;
    
    /**
     * 状态
     */
    private String status;

	/**
     * The default constructor
     */
    public Project() {
    	this.disabled=false;
    	this.status = "课程添加未完成";
    }
    
    public Project(Project oldProject) {
        this.name = oldProject.getName();
        this.code = "p" + new Date().getTime();
        this.firstCategory = oldProject.getFirstCategory();
        this.secondCategory = oldProject.getSecondCategory();
        this.phaseCount = oldProject.getPhaseCount();
        this.projectLead = oldProject.getProjectLead();
        this.department = oldProject.getDepartment();
        this.disabled = false;
        this.beginDate = oldProject.getBeginDate();
        this.endDate = oldProject.getEndDate();
        this.createTime = new Date();
    }
    
    /**
     * @param name
     */
    public Project(String name) {
        this.id = new Long(1);
        this.name = name;
        this.disabled = false;
    }
    
    /**
     * 
     * @param date
     * @param projectLead
     * @return
     */
	public Project init(Date date){
		this.code ="p" + new Date().getTime();
		this.createTime=date;
	
		return this;
	}

    
    /**
     * @param firstCategory
     * @param secondCategory
     * @param department
     * @param date
     * @return
     */
    public Project initialize(TrainingCategory firstCategory, TrainingCategory secondCategory, Department department, Date date) {
        this.firstCategory = firstCategory;
        this.secondCategory = secondCategory;
        this.department = department;
        this.createTime = date;
        return this;
    }
    
    /**
     * 
     * @param minDate
     * @param maxDate
     * @return
     */
    public Project editDate(Date minDate, Date maxDate) {
    	this.beginDate = minDate;
    	this.endDate = maxDate;
    	return this;
    }
    
    /**
     * @param firstCategory
     * @param secondCategory
     * @param department
     * @return
     */
    public Project editInfo(TrainingCategory firstCategory, TrainingCategory secondCategory, Department department) {
        this.firstCategory = firstCategory;
        this.secondCategory = secondCategory;
        this.department = department;
        return this;
    }
    
    /**
     * @param firstCategory
     * @param secondCategory
     * @return
     */
    public Project update(TrainingCategory firstCategory, TrainingCategory secondCategory) {
        this.firstCategory = firstCategory;
        this.secondCategory = secondCategory;
        return this;
    }

    /**
     * @return the id
     */
    public Long getId() {
        return id;
    }


    /**
     * @return the disabled
     */
    public boolean isDisabled() {
        return disabled;
    }

    /**
     * @param id the id to set
     */
    public void setId(Long id) {
        this.id = id;
    }




	/**
	 * @return the name
	 */
	public String getName() {
		return name;
	}

	/**
	 * @param name the name to set
	 */
	public void setName(String name) {
		this.name = name;
	}

	/**
	 * @return the code
	 */
	public String getCode() {
		return code;
	}

	/**
	 * @param code the code to set
	 */
	public void setCode(String code) {
		this.code = code;
	}



	/**
	 * @return the firstCategory
	 */
	public TrainingCategory getFirstCategory() {
		return firstCategory;
	}

	/**
	 * @param firstCategory the firstCategory to set
	 */
	public void setFirstCategory(TrainingCategory firstCategory) {
		this.firstCategory = firstCategory;
	}

	/**
	 * @return the secondCategory
	 */
	public TrainingCategory getSecondCategory() {
		return secondCategory;
	}

	/**
	 * @param secondCategory the secondCategory to set
	 */
	public void setSecondCategory(TrainingCategory secondCategory) {
		this.secondCategory = secondCategory;
	}

	/**
	 * @return the phaseCount
	 */
	public int getPhaseCount() {
		return phaseCount;
	}

	/**
	 * @param phaseCount the phaseCount to set
	 */
	public void setPhaseCount(int phaseCount) {
		this.phaseCount = phaseCount;
	}


	/**
	 * @return the projectLead
	 */
	public String getProjectLead() {
		return projectLead;
	}
	
	public String getProjectLeadEmail() {
        return projectLeadEmail;
    }

	/**
	 * @param projectLead the projectLead to set
	 */
	public void setProjectLead(String projectLead) {
		this.projectLead = projectLead;
	}
	
	public void setProjectLeadEmail(String projectLeadEmail) {
        this.projectLeadEmail = projectLeadEmail;
    }

	/**
	 * @return the department
	 */
	public Department getDepartment() {
		return department;
	}

	/**
	 * @param department the department to set
	 */
	public void setDepartment(Department department) {
		this.department = department;
	}

	/**
	 * @return the beginDate
	 */
	public Date getBeginDate() {
		return beginDate;
	}

	/**
	 * @param beginDate the beginDate to set
	 */
	public void setBeginDate(Date beginDate) {
		this.beginDate = beginDate;
	}

	/**
	 * @return the endDate
	 */
	public Date getEndDate() {
		return endDate;
	}

	/**
	 * @param endDate the endDate to set
	 */
	public void setEndDate(Date endDate) {
		this.endDate = endDate;
	}

	/**
     * @param disabled the disabled to set
     */
    public void setDisabled(boolean disabled) {
        this.disabled = disabled;
    }


	/**
	 * @return the createTime
	 */
	public Date getCreateTime() {
		return createTime;
	}

	/**
	 * @param createTime the createTime to set
	 */
	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	/**
	 * @return the status
	 */
	public String getStatus() {
		return status;
	}

	/**
	 * @param status the status to set
	 */
	public void setStatus(String status) {
		this.status = status;
	}
    

}